home *** CD-ROM | disk | FTP | other *** search
/ PC Graphics Unleashed / PC Graphics Unleashed.iso / ch01 / ati.asm < prev    next >
Assembly Source File  |  1993-09-01  |  7KB  |  275 lines

  1. ; This is file ATIVGA.ASM
  2. ;
  3. ; Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  4. ;
  5. ; This file is distributed under the terms listed in the document
  6. ; "copying.dj", available from DJ Delorie at the address above.
  7. ; A copy of "copying.dj" should accompany this file; if not, a copy
  8. ; should be available from where this file was obtained.  This file
  9. ; may not be distributed without a verbatim copy of "copying.dj".
  10. ;
  11. ; This file is distributed WITHOUT ANY WARRANTY; without even the implied
  12. ; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. ;
  14. ;
  15. ; Modify for the ATI VGA WONDER
  16. ; by Luc Bussieres, bussiere@dmi.usherb.ca
  17. ; University of Sherbrooke
  18. ; March 9th, 1991
  19. ;
  20. ; Version revised by Patrick Daloze, daloze@iro.umontreal.ca
  21. ; University of Montreal
  22. ; Juilly, 4th, 1991
  23. ;
  24.  
  25. cseg    segment byte public 'code'
  26.         assume  cs:cseg, ds:cseg, es:cseg, ss:nothing
  27.         .386
  28.  
  29.         dw      offset init_routine
  30.         dw      offset paging_routine
  31.         dw      1       ; set to 1 if separate read & write windows or
  32.                         ; only 64K of video RAM (ie: no paging)
  33.  
  34. def_tw  dw      80      ; filled in by go32 if GO32 env. var. is set
  35. def_th  dw      25
  36. def_gw  dw      640
  37. def_gh  dw      480
  38. IO_Add  dw      0
  39.  
  40. ;--------------------------------------------------------------------------
  41. ; Entry: AX=mode selection
  42. ;               0=80x25 text
  43. ;               1=default text
  44. ;               2=text CX cols by DX rows
  45. ;               3=biggest text
  46. ;               4=320x200 graphics
  47. ;               5=default graphics
  48. ;               6=graphics CX width by DX height
  49. ;               7=biggest non-interlaced graphics
  50. ;               8=biggest graphics
  51. ;
  52. ; NOTE: This runs in real mode, but don't mess with the segment registers.
  53. ;       For mode 5 to 8 (640x480 or over): only for ATI Version 2 or more
  54. ;       (separate read and write planing).
  55. ;
  56. ; Exit:  CX=width (in pixels or characters)
  57. ;        DX=height
  58.  
  59. init_table      label   word
  60.         dw      offset init_0
  61.         dw      offset init_1
  62.         dw      offset init_2
  63.         dw      offset init_3
  64.         dw      offset init_4
  65.         dw      offset init_5
  66.         dw      offset init_6
  67.         dw      offset init_7
  68.         dw      offset init_8
  69.  
  70. init_routine    proc    far
  71.         cmp     ax,8
  72.         jbe     valid_req
  73.         ret
  74. valid_req:
  75.         shl     ax,1
  76.         mov     bx,ax
  77.         jmp     init_table[bx]
  78.  
  79. init_0: ; 80x25 text
  80.         mov     ax,3
  81.         int     10h
  82.         mov     cx,80
  83.         mov     dx,25
  84.         ret
  85.  
  86. init_1: ; default text
  87.         mov     cx,def_tw
  88.         mov     dx,def_th
  89.         jmp     init_2
  90.  
  91. init_2_table    label   word
  92.         dw      01h, 40, 25
  93.         dw      03h, 80, 25
  94.         dw      23h, 132, 25
  95.         dw      33h, 132, 44
  96. init_2_tend     label   word
  97.  
  98. init_2: ; CX*DX text
  99.         mov     si,offset init_2_table
  100. init_2a:
  101.         cmp     [si+2],cx
  102.         jb      init_2b
  103.         cmp     [si+4],dx
  104.         jb      init_2b
  105.         ; got a big enough one!
  106.         jmp     init_2c
  107. init_2b:
  108.         cmp     si,offset init_2_tend - 6
  109.         je      init_2c
  110.         add     si,6
  111.         jmp     init_2a
  112. init_2c:
  113.         mov     ax,[si]
  114.         push    si
  115.         int     10h
  116.         pop     si
  117.         mov     cx,[si+2]
  118.         mov     dx,[si+4]
  119.         ret
  120.  
  121. init_3: ; biggest text
  122.         mov     ax,[init_2_tend-6]
  123.         int     10h
  124.         mov     cx,[init_2_tend-4]
  125.         mov     dx,[init_2_tend-2]
  126.         ret
  127.  
  128. init_4: ; 320x200 graphics
  129.         mov     ax,13h
  130.         int     10h
  131.         mov     cx,320
  132.         mov     dx,200
  133.         ret
  134.  
  135. init_5: ; default graphics - should be 640x480 if supported
  136.         mov     cx,def_gw
  137.         mov     dx,def_gh
  138.         jmp     init_6
  139.  
  140. init_6_table    label   word
  141.         dw      13h, 320, 200
  142.         dw      61h, 640, 400
  143.         dw      62h, 640, 480
  144.         dw      63h, 800, 600
  145.         dw      64h, 1024, 768
  146. init_6_tend     label   word
  147.  
  148. init_6: ; CX*DX graphics
  149.         mov     si,offset init_6_table
  150. init_6a:
  151.         cmp     [si+2],cx
  152.         jb      init_6b
  153.         cmp     [si+4],dx
  154.         jb      init_6b
  155.         ; got a big enough one!
  156.         jmp     init_6c
  157. init_6b:
  158.         cmp     si,offset init_6_tend - 6
  159.         je      init_6c
  160.         add     si,6
  161.         jmp     init_6a
  162. init_6c:
  163.         mov     ax,[si]
  164.         push    si
  165.         int     10h
  166.         pop     si
  167.         mov     cx,[si+2]
  168.         mov     dx,[si+4]
  169.  
  170.         push    ax
  171.         push    dx
  172.         mov     dx,01ceh   ; ATI register : ensure that separed R/W is enable
  173.         mov     al,0beh    ; Register 2
  174.         out     dx,al
  175.         inc     dx
  176.         in      al,dx
  177.         dec     dx
  178.         mov     ah,al
  179.         or      ah,008h    ; set R/W enable
  180.         mov     al,0beh
  181.         out     dx,ax
  182.         pop     dx
  183.         pop     ax
  184.  
  185.         ret
  186.  
  187. init_7: ; biggest non-interlaced graphics
  188.         mov     ax,63h
  189.         int     10h
  190.         mov     cx,800
  191.         mov     dx,600
  192.  
  193.         push    ax
  194.         push    dx
  195.         mov     dx,01ceh   ; ATI register : ensure that separed R/W is enable
  196.         mov     al,0beh    ; Register 2
  197.         out     dx,al
  198.         inc     dx
  199.         in      al,dx
  200.         dec     dx
  201.         mov     ah,al
  202.         or      ah,008h    ; set R/W enable
  203.         mov     al,0beh
  204.         out     dx,ax
  205.         pop     dx
  206.         pop     ax
  207.  
  208.         ret
  209.  
  210. init_8: ; biggest graphics
  211.         mov     ax,63h
  212.         int     10h
  213.         mov     cx,800
  214.         mov     dx,600
  215.  
  216.         push    ax
  217.         push    dx
  218.         mov     dx,01ceh   ; ATI register : ensure that separed R/W is enable
  219.         mov     al,0beh    ; Register 2
  220.         out     dx,al
  221.         inc     dx
  222.         in      al,dx
  223.         dec     dx
  224.         mov     ah,al
  225.         or      ah,008h    ; set R/W enable
  226.         mov     al,0beh
  227.         out     dx,ax
  228.         pop     dx
  229.         pop     ax
  230.  
  231.         ret
  232.  
  233. init_routine    endp
  234.  
  235. ;--------------------------------------------------------------------------
  236. ; Entry: AH=read page
  237. ;        AL=write page
  238. ;
  239. ; NOTE: This runs in protected mode!  Don't mess with the segment registers!
  240. ; This code must be relocatable and may not reference any data!
  241. ;
  242. ; Exit: VGA configured.
  243. ;       AX,BX,CX,DX,SI,DI may be trashed
  244. ;
  245. ; Source: Advanced Programmer's Guide To SuperVGAs
  246. ;
  247.  
  248.         assume  ds:nothing, es:nothing
  249.  
  250. paging_routine  proc    FAR
  251.  
  252.         mov     bx, ax
  253.         and     ah,07h          ; Read-plane on bits 7-6-5
  254.         ror     ah,1
  255.         ror     ah,1
  256.         ror     ah,1
  257.         and     bh, 08
  258.         shr     bh, 3
  259.  
  260.         and     al,0Fh          ; Write-plane on bits 3-2-1
  261.         shl     al,1
  262.         
  263.  
  264.         or      ah,al           ; Combine Read and Write plane
  265.         or      ah, bh
  266.  
  267.         mov     dx,01ceh        ; ATI register
  268.         mov     al,0b2h         ; plane select
  269.         out     dx,ax
  270.         ret
  271. paging_routine  endp
  272.  
  273. cseg    ends
  274.         end
  275.